package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.Model.EmployeeModel;
import com.hlw.hr_man.service.FindCardService;
import com.hlw.hr_man.serviceImpl.FindCardServiceImpl;

public class AddCardcontroller extends HttpServlet{
	FindCardService acs = new FindCardServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		resp.setContentType("text/html;charset=UTF-8");
		HttpSession session = req.getSession();
		PrintWriter  pw =  resp.getWriter();
		String card_company  = req.getParameter("card_company");
		String card_address  = req.getParameter("card_address");
		String card_tel  = req.getParameter("card_tel");
		String card_email  = req.getParameter("card_email");
		int e_id = (int)session.getAttribute("employeeid");
		EmployeeModel employee = new EmployeeModel(e_id, card_company, card_address, card_tel, card_email);
		if(acs.isHaveCard(e_id)==false){
			pw.write(acs.addCard(employee));
		}else{
			pw.write("1");
		}
	}
}
